<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>礼品详情</title>
    <script type="text/javascript" src="/js/jquery.js"></script>
</head>
<body>

<div>
    <div id = "J_title">奖品名称: </div>
    <div id="J_pic">封面图片:  </div>
    <div id = "J_point">所需要积分:  </div>
    <div id = "J_price">市场价格:  </div>
    <div id = "J_stock">奖品库存:  </div>
    <div id = "J_content">详情描述:   </div>
    <div id = "J_exchange">已兑换数:   </div>
    <div id = "J_picList">

    </div>

    <div id="J_contents">

    </div>
</div>
<script>
$(function(){
    var id = "${id}";
    var data = {id:id};
    var url = "/product/product_detail";
    $.ajax({
        type: "POST",
        async: false,
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(data),
        url: url,
        success: function(res){
            if(res.code == 200){
                console.log(res);
                var product = res.data.product;
                var pic_list = res.data.pic_list;
                var product_content = res.data.product_content;
                if(product.isup==1){
                    alert("该产品已经下架，不能兑换");
                }
                console.log(pic_list);
                $("#J_title").append(product.title);
                $("#J_point").append(product.point);
                $("#J_price").append(product.price);
                $("#J_stock").append(product.stock);
                $("#J_content").append(product.content);
                $("#J_exchange").append(product.exchange);
                $("#J_pic").append('<img src="'+product.pic+'" alt="" width="50px" height="50px">');
                if(pic_list.length>0){
                    for(var i in pic_list) {
                        var shtml = ' <li><img src="'+pic_list[i]+'" alt="" width="50px" height="50px"></li>';
                        $("#J_picList").append(shtml);
                    }
                }

                if(product_content.length>0){
                    for (var j =0;j<product_content.length;j++){
                        var html = '';
                        if(product_content[j]['type'] == 0){
                            html = product_content[j]['content'];
                        }else{
                            html ='<img src="'+product_content[j]['content']+'" alt="" width="50px" height="50px">';
                        }
                        $("#J_contents").append(html);
                    }
                }
            }else{
                alert(res.msg);
            }
        },
        error: function(){

        },
        complete: function(){
        }
    });
});
</script>
</body>
</html>
